import { Controller, Post, Body, UseFilters } from '@nestjs/common';
import { AuthService } from './auth.service';
import { Public } from './public.decorator';
import { HttpExceptionFilter } from 'src/exception/http-exception.filter'
import { wrapperResponse } from '../utils/index'

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {
  };

  @Public()
  @Post('login')
  @UseFilters(new HttpExceptionFilter())
  login(@Body() params) {

    return wrapperResponse(this.authService.login(params.userName, params.userPwd), '登录成功');
  }
  // ✅ 刷新 access_token
  @Public()
  @Post('refresh')
  async refresh(@Body() body: { refresh_token: string }) {
    const result = await this.authService.refreshToken(body.refresh_token);
    console.log(result, 'result');

    return wrapperResponse(Promise.resolve(result), '刷新 token 成功');
  }
}
